package org.scohen.juploadr.uploadapi.flickrrest.upload;

import java.util.SortedMap;
import java.util.TreeMap;

import org.scohen.juploadr.uploadapi.CommunicationException;
import org.scohen.juploadr.uploadapi.ProtocolException;
import org.scohen.juploadr.uploadapi.flickrrest.DefaultFlickrHandler;
import org.scohen.juploadr.uploadapi.flickrrest.FlickrMethod;
import org.scohen.juploadr.uploadapi.flickrrest.RestFlickrApi;
import org.scohen.juploadr.uploadapi.flickrrest.authentication.FlickrAccount;

public class GetUploadStatus extends FlickrMethod {
    private FlickrAccount account;

    public GetUploadStatus(FlickrAccount account) {
        this.account = account;
    }

    /**
     * @return Returns the maxBandwidth.
     */
    public long getMaxBandwidth() {
        return account.getMonthlyUploadLimit();
    }

    /**
     * @param maxBandwidth
     *            The maxBandwidth to set.
     */
    public void setMaxBandwidth(long maxBandwidth) {
        account.setMonthlyUploadLimit(maxBandwidth);
    }

    /**
     * @return Returns the pro.
     */
    public boolean isPro() {
        return account.isPro();
    }

    /**
     * @param pro
     *            The pro to set.
     */
    public void setPro(boolean pro) {
        account.setPro(pro);
    }

    /**
     * @return Returns the usedBandwidth.
     */
    public long getUsedBandwidth() {
        return account.getCurrentUploadUsed();
    }

    /**
     * @param usedBandwidth
     *            The usedBandwidth to set.
     */
    public void setUsedBandwidth(long usedBandwidth) {
        account.setCurrentUploadUsed(usedBandwidth);
    }

    public DefaultFlickrHandler getResponseHandler() {
        return new GetUploadStatusHandler(this);
    }

    public SortedMap<String, String> getParams() {
        SortedMap<String, String> map = new TreeMap<String, String>();
        map.put("method", "flickr.people.getUploadStatus");
        map.put("api_key", RestFlickrApi.FLICKR_API_KEY);
        return map;
    }

    public boolean isAuthorized() {
        return true;
    }

    public void setUsername(String username) {
        account.setUsername(username);
        account.setName(username);
    }

    public String getUsername() {
        return account.getUsername();
    }

    public boolean isUnlimited() {
        return account.isUnlimited();
    }

    public void setUnlimited(boolean unlimited) {
        account.setUnlimited(unlimited);
    }

    @Override
    public boolean execute() throws ProtocolException, CommunicationException {
        boolean success = super.execute();
        account.save();
        return success;
    }

    @Override
    protected ProtocolException buildProtocolException(int errorCode) {
        // this method only generates the default exceptions
        return null;
    }
    
    

}
